namespace SageKing.Database.Contracts;

/// <summary>
/// 框架实体基类Id
/// </summary>
public interface IEntityBaseId<T> : ICloneable
{
    public T Id { get; set; }
}

/// <summary>
/// 乐观并发控制
/// </summary>
public interface IEntityLockRowVersion
{
    /// <summary>
    /// 乐观并发控制 
    ///  [Timestamp]   数据注解方式
    ///  使用 Fluent API 配置​（可选，如果不用数据注解）
    ///    .Property(p => p.RowVersion)
    ///    .IsRowVersion(); // 对于 SQL Server
    /// 或者对于其他数据库，可能需要使用 .IsConcurrencyToken()
    /// </summary>
    [Timestamp]
    public byte[] RowVersion { get; set; }
}

public interface IEntityVersionValidation
{
    /// <summary>
    /// 标识版本字段
    /// 注意：只能是实体更新不能是集合更新
    /// 防止提交覆盖，重复提交
    /// </summary>
    public long Version { get; set; }
}

public interface IEntityBase<T> : IEntityBaseId<T>, IDeletedFilter
{
    public DateTime CreateTime { get; }

    public DateTime? UpdateTime { get; }

    /// <summary>
    /// 创建者Id
    /// </summary>
    public long? CreateUserId { get; }

    /// <summary>
    /// 创建者姓名
    /// </summary>
    public string? CreateUserName { get; }

    /// <summary>
    /// 修改者Id
    /// </summary>
    public long? UpdateUserId { get; }

    /// <summary>
    /// 修改者姓名
    /// </summary>
    public string? UpdateUserName { get; }

    /// <summary>
    /// 软删除
    /// </summary>
    public bool IsDelete { get; }
}

/// <summary>
/// 业务数据实体基类（数据权限）
/// </summary>
public interface IEntityBaseData<T, Torg> : IEntityBase<T>, IOrgIdFilter<Torg>
{
    /// <summary>
    /// 创建者部门Id
    /// </summary>
    public Torg? CreateOrgId { get; }

    /// <summary>
    /// 创建者部门名称
    /// </summary>
    public string? CreateOrgName { get; }
}

/// <summary>
/// 租户实体基类
/// </summary>
public interface IEntityTenant<T, Tt> : IEntityBase<T>, ITenantIdFilter<Tt>
{
    /// <summary>
    /// 租户Id
    /// </summary>
    public Tt? TenantId { get; }
}

/// <summary>
/// 租户实体基类Id
/// </summary>
public interface IEntityTenantId<T, Tt> : IEntityBaseId<T>, ITenantIdFilter<Tt>
{
    /// <summary>
    /// 租户Id
    /// </summary>
    public Tt? TenantId { get; }
}

/// <summary>
/// 租户实体基类 + 业务数据（数据权限）,
/// </summary>
public interface IEntityTenantBaseData<T, Tt> : IEntityBaseData<T, Tt>, ITenantIdFilter<Tt>
{
    /// <summary>
    /// 租户Id
    /// </summary>
    public Tt? TenantId { get; }
}

#region 模板实体基类
/// <summary>
/// 模板实体基类
/// </summary>
public interface IEntityTemplate<T, Tt> : IEntityBase<T>, ISort, IEnableFilter
{
    /// <summary>
    /// 模板Id
    /// </summary>
    public Tt? TemplateId { get; }
    /// <summary>
    /// 模板名称
    /// </summary>
    public string Name { get; }
}

/// <summary>
/// 排序
/// </summary>
public interface ISort
{
    /// <summary>
    /// 序号
    /// </summary>
    public int? SortNo { get; set; }
    /// <summary>
    /// 排序
    /// </summary>
    public int? OrderNo { get; set; }
}

public interface IJsonColumn
{
    /// <summary>
    /// Json属性 字典值
    /// dictionary
    /// </summary>
    public string JsonDicColumn { get; set; }
}

/// <summary>
/// 模板实体配置基类
/// </summary>
public interface IEntityTemplateConfig<T, Tt> : IEntityBase<T>, ISort, IJsonColumn, IEnableFilter
{
    /// <summary>
    /// 模板Id
    /// </summary>
    public Tt? TemplateId { get; }
    /// <summary>
    /// 来源名称
    /// </summary>
    public TemplateSourceEnum SourceType { get; }
    /// <summary>
    /// 配置主键
    /// </summary>
    public string KKey { get; }
    /// <summary>
    /// 配置值
    /// </summary>
    public string VValue { get; }
    /// <summary>
    /// 编码
    /// </summary>
    public string Code { get; }
}
/// <summary>
/// 租户+模板实体数据
/// </summary>
public interface IEntityTenantTemplateData<T, Tt> : IEntityTenantBaseData<T, Tt>, ITenantIdFilter<Tt>, ISort, IEnableFilter
{
    /// <summary>
    /// 模板Id
    /// </summary>
    public Tt? TemplateId { get; }
    /// <summary>
    /// 模板名称 来源于模板实体基类，可改，用于配置参数（如：模板名称）
    /// </summary>
    public string Name { get; }
    /// <summary>
    /// 模板显示标题
    /// </summary>
    public string Title { get; }
}
#endregion